﻿using System;
using System.Net.Http.Headers;
using IListNode;

namespace _617_merge_two_binary_trees
{
    class Program
    {
        static void Main (string[] args)
        {
            TreeNode T1 = new TreeNode (1);
            T1.left = new TreeNode (3);
            T1.right = new TreeNode (2);
            T1.left.left = new TreeNode (5);

            TreeNode T2 = new TreeNode (2);
            T2.left = new TreeNode (1);
            T2.right = new TreeNode (3);
            T2.left.right = new TreeNode (4);
            T2.right.right = new TreeNode (7);

            TreeNode root = new Solution ().MergeTrees (T1, T2);

            Console.WriteLine ();
        }
    }

    public class Solution
    {
        public TreeNode MergeTrees (TreeNode t1, TreeNode t2)
        {
            if (t1 == null) return t2;
            if (t2 == null) return t1;

            t1.val += t2.val;
            t1.left = MergeTrees (t1.left, t2.left);
            t1.right = MergeTrees (t1.right, t2.right);

            return t1;
        }

        
    }
}
